//
//  CastingEarningsRecordCell.swift
//  SCA
//
//  Created by tjun on 2025/9/20.
//

import UIKit


struct CastingEarningsRecordModel {
    let date: String
    let amount: String
    let sortKey: String
}

class CastingEarningsRecordView: UIView {
    
    let dateLabel = UILabel(font: UIFontMake(14), textColor: UIColor.white, textAlignment: .left)
    let amountLabel = UILabel(font: UIFontMake(14), textColor: UIColor.white, textAlignment: .right)
    
    override init(frame: CGRect) {
        super.init(frame: frame)

        let contentView = UIView().addTo(self)
        contentView.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(12)
            make.top.bottom.equalToSuperview()
        }

        contentView.addSubview(dateLabel)
        dateLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.centerY.equalToSuperview()
        }

        contentView.addSubview(amountLabel)
        amountLabel.snp.makeConstraints { (make) in
            make.right.equalToSuperview()
            make.centerY.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}


class CastingEarningsRecordCell: BaseTableViewCell {
    
    var model: CastingEarningsRecordModel! {
        didSet {
            earningsRecordView.dateLabel.text = model.date
            earningsRecordView.amountLabel.text = model.amount
        }
    }
    
    var indexPath: IndexPath? {
        didSet {
            guard let indexPath = indexPath else { return }
            if indexPath.row % 2 == 0 {
                earningsRecordView.backgroundColor = .clear
            } else {
                earningsRecordView.backgroundColor = UIColorMake(0x2E3036)
            }
        }
    }

    private let earningsRecordView = CastingEarningsRecordView()
 
    override func setSubView() {
        super.setSubView()
        
        selectionStyle = .none
        
        backgroundColor = AppStyle.color.background
        
        earningsRecordView.addCorner(radius: 10)
        earningsRecordView.backgroundColor = UIColorMake(0x2E3036)
        contentView.addSubview(earningsRecordView)
        earningsRecordView.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(AppStyle.margin.left)
            make.top.bottom.equalToSuperview()
        }

    }
}


